package com.corx.network.core.type;


import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author gx
 * @version 1.0.0
 */
public enum NetworkTypeEnum {

    /**
     * Mqtt类型
     */
    MQTT_CLIENT("MQTT客户端", "mqtt_client"),
    ;

    /**
     * 名称
     */
    private final String name;


    /**
     * 类型
     */
    private final String type;

    NetworkTypeEnum(String name, String type) {
        this.name = name;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }

    /**
     * 获取网络类型枚举
     *
     * @param type type
     * @return NetworkType
     */
    public static NetworkTypeEnum getByType(String type) {

        for (NetworkTypeEnum value : values()) {
            if (value.type.equalsIgnoreCase(type)) {
                return value;
            }
        }
        return null;
    }

    @JsonCreator
    public static NetworkTypeEnum forValue(String value) {
        for (NetworkTypeEnum type : values()) {
            if (type.type.equals(value)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的枚举值: " + value);
    }


}
